

using System;
using System.Runtime.InteropServices;

namespace CUtil.Win32
{
	/// <summary> 
	/// 
	/// </summary>
	[System.Security.SuppressUnmanagedCodeSecurity()]
	public class Gdi32 {

		/// <summary> 
		/// Do not create instances of this class!
		/// </summary>
		private Gdi32() {
		}

#region enums
		// Draw Text format flags
		#region
		/// <summary>
		/// 
		/// </summary>
		public enum DrawTextFormatFlags
		{
			/// <summary>
			/// 
			/// </summary>
			DT_TOP              = 0x00000000,
			/// <summary>
			/// 
			/// </summary>
			DT_LEFT             = 0x00000000,
			/// <summary>
			/// 
			/// </summary>
			DT_CENTER           = 0x00000001,
			/// <summary>
			/// 
			/// </summary>
			DT_RIGHT            = 0x00000002,
			/// <summary>
			/// 
			/// </summary>
			DT_VCENTER          = 0x00000004,
			/// <summary>
			/// 
			/// </summary>
			DT_BOTTOM           = 0x00000008,
			/// <summary>
			/// 
			/// </summary>
			DT_WORDBREAK        = 0x00000010,
			/// <summary>
			/// 
			/// </summary>
			DT_SINGLELINE       = 0x00000020,
			/// <summary>
			/// 
			/// </summary>
			DT_EXPANDTABS       = 0x00000040,
			/// <summary>
			/// 
			/// </summary>
			DT_TABSTOP          = 0x00000080,
			/// <summary>
			/// 
			/// </summary>
			DT_NOCLIP           = 0x00000100,
			/// <summary>
			/// 
			/// </summary>
			DT_EXTERNALLEADING  = 0x00000200,
			/// <summary>
			/// 
			/// </summary>
			DT_CALCRECT         = 0x00000400,
			/// <summary>
			/// 
			/// </summary>
			DT_NOPREFIX         = 0x00000800,
			/// <summary>
			/// 
			/// </summary>
			DT_INTERNAL         = 0x00001000,
			/// <summary>
			/// 
			/// </summary>
			DT_EDITCONTROL      = 0x00002000,
			/// <summary>
			/// 
			/// </summary>
			DT_PATH_ELLIPSIS    = 0x00004000,
			/// <summary>
			/// 
			/// </summary>
			DT_END_ELLIPSIS     = 0x00008000,
			/// <summary>
			/// 
			/// </summary>
			DT_MODIFYSTRING     = 0x00010000,
			/// <summary>
			/// 
			/// </summary>
			DT_RTLREADING       = 0x00020000,
			/// <summary>
			/// 
			/// </summary>
			DT_WORD_ELLIPSIS    = 0x00040000
		}
		
			#endregion

		// Background Mode
		#region
		/// <summary>
		/// 
		/// </summary>
		public enum BackgroundMode
		{
			/// <summary>
			/// 
			/// </summary>
			TRANSPARENT = 1,
			/// <summary>
			/// 
			/// </summary>
			OPAQUE = 2
		}
		#endregion

		/// <summary>Raster operations for the BitBlt function.</summary>
		public enum RasterOps {
			/// <summary>dest = source</summary>
			SRCCOPY             = 0x00CC0020,
			/// <summary>dest = source OR dest</summary>
			SRCPAINT            = 0x00EE0086,
			/// <summary>dest = source AND dest</summary>
			SRCAND              = 0x008800C6,
			/// <summary>dest = source XOR dest</summary>
			SRCINVERT           = 0x00660046,
			/// <summary>dest = source AND (NOT dest )</summary>
			SRCERASE            = 0x00440328,
			/// <summary>dest = (NOT source)</summary>
			NOTSRCCOPY          = 0x00330008,
			/// <summary>dest = (NOT src) AND (NOT dest)</summary>
			NOTSRCERASE         = 0x001100A6,
			/// <summary>dest = (source AND pattern)</summary>
			MERGECOPY           = 0x00C000CA,
			/// <summary>dest = (NOT source) OR dest</summary>
			MERGEPAINT          = 0x00BB0226,
			/// <summary>dest = pattern</summary>
			PATCOPY             = 0x00F00021,
			/// <summary>dest = DPSnoo</summary>
			PATPAINT            = 0x00FB0A09,
			/// <summary>dest = pattern XOR dest</summary>
			PATINVERT           = 0x005A0049,
			/// <summary>dest = (NOT dest)</summary>
			DSTINVERT           = 0x00550009,
			/// <summary>dest = BLACK</summary>
			BLACKNESS           = 0x00000042,
			/// <summary>dest = WHITE</summary>
			WHITENESS           = 0x00FF0062,
			/// <summary>Do not Mirror the bitmap in this call</summary>
			NOMIRRORBITMAP      = unchecked((int)0x80000000),
			/// <summary>Include layered windows</summary>
			CAPTUREBLT          = 0x40000000,
		}

#endregion enums
				
#region constants
#endregion constants

#region structs
	/// <summary><A HREF="ms-help://MS.VSCC/MS.MSDNVS/gdi/bitmaps_0zn6.htm">see Platform SDK</A></summary>
	[StructLayout(LayoutKind.Sequential)]
	public struct BITMAPINFO {
		/// <summary></summary>
		// [MarshalAs(UnmanagedType.Struct)] public BITMAPINFOHEADER header;
		public Int32 biSize;
		/// <summary></summary>
		public Int32 biWidth;
		/// <summary></summary>
		public Int32 biHeight;
		/// <summary></summary>
		public Int32 biPlanes;
		/// <summary></summary>
		public Int32 biBitCount;
		/// <summary></summary>
		public Int32 biCompression;
		/// <summary></summary>
		public Int32 biSizeImage;
		/// <summary></summary>
		public Int32 biXPelsPerMeter;
		/// <summary></summary>
		public Int32 biYPelsPerMeter;
		/// <summary></summary>
		public Int32 biClrUsed;
		/// <summary></summary>
		public Int32 biClrImportant;
		/// <summary></summary>
		[MarshalAs(UnmanagedType.ByValArray, SizeConst=256)] public Int32[] bmiColors;
	}

	/// <summary><A HREF="ms-help://MS.VSCC/MS.MSDNVS/gdi/bitmaps_1rw2.htm">see Platform SDK</A></summary>
	[StructLayout(LayoutKind.Sequential)]
	public struct BITMAPINFOHEADER
	{
		/// <summary></summary>
		public Int32 biSize;
		/// <summary></summary>
		public Int32 biWidth;
		/// <summary></summary>
		public Int32 biHeight;
		/// <summary></summary>
		public Int32 biPlanes;
		/// <summary></summary>
		public Int32 biBitCount;
		/// <summary></summary>
		public Int32 biCompression;
		/// <summary></summary>
		public Int32 biSizeImage;
		/// <summary></summary>
		public Int32 biXPelsPerMeter;
		/// <summary></summary>
		public Int32 biYPelsPerMeter;
		/// <summary></summary>
		public Int32 biClrUsed;
		/// <summary></summary>
		public Int32 biClrImportant;
	};

	/// <summary><A HREF="ms-help://MS.VSCC/MS.MSDNVS/gdi/bitmaps_0zn6.htm">see Platform SDK</A></summary>
	[StructLayout(LayoutKind.Sequential)]
	public struct BITMAPINFO2
	{
		/// <summary>...</summary>
		[MarshalAs(UnmanagedType.Struct)] public BITMAPINFOHEADER bmiHeader;
		/// <summary>...</summary>
		[MarshalAs(UnmanagedType.ByValArray, SizeConst=256)] public Int32[] bmiColors;
	}

#endregion structs

#region functions
		/// <summary>BitBlt call</summary>
		[DllImport("gdi32")]
		public static extern bool BitBlt(
			IntPtr hDC,
			int x,
			int y,
			int nWidth,
			int nHeight,
			IntPtr hSrcDC,
			int xSrc,
			int ySrc,
			int dwRop);
	
		/// <summary>BitBlt call</summary>
		[DllImport("gdi32")]
		public static extern bool BitBlt(
			IntPtr hDC,
			int x,
			int y,
			int nWidth,
			int nHeight,
			IntPtr hSrcDC,
			int xSrc,
			int ySrc,
			RasterOps dwRop);
	
		/// <summary></summary>
		[DllImport("gdi32")]
		public static extern IntPtr CreateCompatibleBitmap(
			IntPtr hDC,
			int width,
			int height);

		/// <summary></summary>
		[DllImport("gdi32")]
		public static extern IntPtr CreateCompatibleDC(IntPtr hDC);

		/// <summary></summary>
		[DllImport("gdi32")]
		public static extern IntPtr CreateDIBSection(
			IntPtr hdc,
			[MarshalAs(UnmanagedType.Struct)] ref BITMAPINFO2 bmi,
			int iUsage,
			ref int ppvBits,
			IntPtr hSection,
			int dwOffset);

		/// <summary></summary>
		[DllImport("gdi32")]
		public static extern bool DeleteDC(IntPtr hDC);

		/// <summary></summary>
		[DllImport("gdi32")]
		public static extern bool DeleteObject(IntPtr hObject);

		/// <summary>
		/// 
		/// </summary>
		[DllImport("user32.dll", CharSet=CharSet.Auto)]
		public extern static int DrawText(IntPtr hdc, string lpString, int nCount, ref User32.RECT lpRect, int uFormat);
            
		/// <summary>GetDIBits call.</summary>
		[DllImport("gdi32")]
		public static extern int GetDIBits(
			IntPtr hdc,
			IntPtr hbm,
			int arg1,
			int arg2,
			int arg3,
			[MarshalAs(UnmanagedType.Struct)] ref BITMAPINFO2 bmi,
			int arg5);
		/// <summary>
		/// 
		/// </summary>
		[DllImport("gdi32.dll")]
		static public extern uint GetPixel(IntPtr hDC, int XPos, int YPos);

		/// <summary></summary>
		[DllImport("gdi32")]
		public static extern int GetObjectType(IntPtr hobject);

		/// <summary></summary>
		[DllImport("gdi32")]
		public static extern IntPtr SelectObject(IntPtr hdc, IntPtr obj);

		/// <summary>
		/// Set mapping mode of a DC
		/// </summary>
		[DllImport("gdi32")]
		public static extern int SetMapMode( IntPtr hdc, int fnMapMode);

		/// <summary>
		/// 
		/// </summary>
		[DllImport("gdi32")]
		public static extern int SetBkMode(IntPtr hDC, BackgroundMode mode);

		/// <summary>Sets the viewport origin for a GDI hdc.</summary>
		[DllImport("gdi32.dll", CharSet=CharSet.Auto)]
		public static extern bool OffsetViewportOrgEx(IntPtr hdc, int ofsX, int ofsY, IntPtr prev);


#endregion functions
	}
}


